/*
 * @Description:
 * @Author: ldx
 * @Date: 2022-04-06 14:45:22
 * @LastEditors: ldx
 * @LastEditTime: 2023-12-13 14:46:34
 */
// import { Layout } from 'antd'
import React, { Suspense, useEffect } from 'react'
// const { Footer } = Layout
import {
  Route,
  Routes,
  useLocation,
  useNavigate
  // useParams
} from 'react-router-dom'
import { useRecoilState, useSetRecoilState } from 'recoil'

import { RouteLoading } from '@/components'
import { commonState } from '@/recoil'
import { getToken } from '@/utils'

// import styles from './index.module.less'
import routes from './routes'
const RouteList: React.FC = () => {
  // const navigate = useNavigate()
  // const params = useParams()
  const location = useLocation()
  const [isLogin, setIsLogin] = useRecoilState(commonState.isLogin)
  const isToken = !!getToken()
  useEffect(() => {
    if (isToken) {
      setIsLogin(true)
    } else {
      setIsLogin(false)
    }
    if (!isToken && location.pathname != '/register') {
      // navigate('/login' + location.search)
    }
    console.log('index', isToken)
  }, [isLogin])

  useEffect(() => {
    if (!isToken) return
  }, [])

  return (
    <Suspense fallback={<RouteLoading />}>
      <Routes>
        {(routes || []).map((route) => {
          const Component = route.component
          return (
            <Route path={route.path} element={<Component />} key={route.key} />
          )
        })}
      </Routes>
    </Suspense>
  )
}

export default RouteList
